package com.beauty.dressing.module.mine.persenter;

import com.beauty.dressing.common.base.BasePresenter;
import com.beauty.dressing.common.bean.BaseObserver;
import com.beauty.dressing.common.bean.BaseParse;
import com.beauty.dressing.common.bean.LeaseReadyPayResultBean;
import com.beauty.dressing.common.bean.OrderBean;
import com.beauty.dressing.module.mine.persenter.contract.OrderContract;
import com.beauty.dressing.rxandroid.api.ApiManager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class OrderPresenter extends BasePresenter implements OrderContract.Presenter {
    private static final String TAG = "OrderPresenter";
    private OrderContract.ViewControl mViewControl;

    public OrderPresenter(OrderContract.ViewControl mViewControl) {
        this.mViewControl = mViewControl;
    }

    @Override
    public void leaseOrder(String member_id, String type, String token, String page) {
        mViewControl.showProgress();
        Map<String, String> map = new HashMap<>();
        map.put("member_id", member_id);
        map.put("type", type);
        map.put("token", token);
        map.put("page", "1");
        ApiManager.getInstence().getLeaseService().leaseOrder(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<Object, OrderBean>() {
                    @Override
                    protected void onSuccees(String message, Object data, List<OrderBean> list, BaseParse extra) {
                        mViewControl.onLeaseOrder(true, 200, message, list);
                    }

                    @Override
                    protected void onFailed(int code, String message, Object data, List<OrderBean> list, BaseParse extra) {
                        mViewControl.onLeaseOrder(false, code, message, list);
                    }
                });
    }

    @Override
    public void leaseReadyPay(long member_id, String token, long leaseId, long order_id, String take_way, String name, String address, String phone) {
        Map<String, String> map = httpParams.getHeaderMap();
        map.put("member_id", String.valueOf(member_id));
        map.put("token", String.valueOf(token));
        map.put("lease_id", String.valueOf(leaseId));
        map.put("order_id", String.valueOf(order_id));
        map.put("take_way", String.valueOf(take_way));
        map.put("name", String.valueOf(name));
        map.put("address", String.valueOf(address));
        map.put("phone", String.valueOf(phone));
        ApiManager.getInstence().getOrderServie().leaseReadyPay(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<LeaseReadyPayResultBean, Object>() {

                    @Override
                    protected void onSuccees(String message, LeaseReadyPayResultBean data, List<Object> list, BaseParse extra) {
                        if (isDestoryed) return;
                        mViewControl.onLeaseReadyPay(true, 200, message, data);
                    }

                    @Override
                    protected void onFailed(int code, String message, LeaseReadyPayResultBean data, List<Object> list, BaseParse extra) {
                        if (isDestoryed) return;
                        mViewControl.onLeaseReadyPay(false, code, message, data);
                    }
                });
    }

}
